package com.bbs.service.impl;

import com.bbs.domain.Comment;
import com.bbs.mapper.CommentMapper;
import com.bbs.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @ClassName CommentServiceImpl
 * @Description TODO 评论表
 * @Author chen hong wei
 * @Date 2019/9/22 19:33
 */
@Service
public class CommentServiceImpl implements CommentService {


    @Autowired
    private CommentMapper commentMapper;

    /**
     * @return java.util.List<com.bbs.domain.Comment>
     * @author chen hong wei
     * @Description 根据帖子id查询评论
     * @Date 19:56 2019/9/22
     * @Param [articleid]
     **/
    @Override
    public List<Comment> findByArticleId(Integer articleId) {
        Example example = new Example(Comment.class);
        Example.Criteria criteria = example.createCriteria();
        //帖子id
        criteria.andEqualTo("articleid", articleId);
        example.setOrderByClause("commenttime desc");
        List<Comment> comments = commentMapper.selectByExample(example);
        if(comments==null&&comments.size()==0){
            return null;
        }
        return  comments;

    }
}